/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonpackage;

import java.util.Vector;

/**
 *
 * @author chuda
 */
public class POI {

    private int id; //unique id number
    private String type; //type for identifying subtype within essential types
    private String description; //description
    private boolean ticket; //specify if ordering is enabled
    private Position position; //POI's position
    private String telephone;
    private String address;
    private String url;
    private Vector orders; //orders which correspond to this POI
    private Vector tags;

    public POI() {
    }

    /**
     * Default constructor
     * @param type
     * @param descr
     * @param ticket
     * @param pos
     */
    public POI(String type, String descr, String address, String telephone, boolean order, Position pos) {
        this.type = type;
        this.description = descr;
        this.ticket = order;
        this.position = pos;
        this.address = address;
        this.telephone = telephone;
    }

    /**
     * returns distance of this poi by provided Position object
     * @param pos position from which the distance is needed
     * @return double distance of this poi from provided position
     */
    public double getDistance(Position pos) {
        double dist = 0;
        double x = pos.getLatitude() - this.position.getLatitude();
        double y = pos.getLongitude() - this.position.getLongitude();
        dist = Math.sqrt(x * x + y * y);
        return dist;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the ticket
     */
    public boolean isTicket() {
        return ticket;
    }

    /**
     * @param ticket the ticket to set
     */
    public void setTicket(boolean order) {
        this.ticket = order;
    }

    /**
     * @return the position
     */
    public Position getPosition() {
        return position;
    }

    /**
     * @param position the position to set
     */
    public void setPosition(Position position) {
        this.position = position;
    }

    public void addOrder(Order order) {
        if (this.orders == null) {
            orders = new Vector();
            orders.addElement(order);
            this.setOrders(orders);
        } else {
            orders.addElement(order);
            this.setOrders(orders);
        }
    }

    public void addTag(Tag tag) {
        if (this.tags == null) {
            tags = new Vector();
            tags.addElement(tag);
            this.setTags(tags);
        } else {
            tags.addElement(tag);
            this.setTags(tags);
        }
    }

    /**
     * @return the orders
     */
    public //POI's position
            Vector getOrders() {
        return orders;
    }

    /**
     * @param orders the orders to set
     */
    public void setOrders(Vector orders) {
        this.orders = orders;
    }

    /**
     * @return the tags
     */
    public Vector getTags() {
        return tags;
    }

    /**
     * @param tags the tags to set
     */
    public void setTags(Vector tags) {
        this.tags = tags;
    }

    /**
     * @return the telephone
     */
    public String getTelephone() {
        return telephone;
    }

    /**
     * @param telephone the telephone to set
     */
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    public String toString() {
        //String type,String descr, String address, String telephone, boolean order
        String ret = this.type + "#" + this.description + "#" + this.address + "#" + this.telephone + "#" + this.ticket + "#";
        ret += this.position.toString() + "#";
        try {
            ret += "num_orders: " + orders.size() + "#";
        } catch (Exception e) {
            ;
        }
        for (int i = 0; i < orders.size(); i++) {
            if (i == orders.size()) {
                ret += orders.get(i).toString();
            }
            ret += orders.get(i).toString() + "#";
        }
        return ret;

    }
}
